//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "NullParameter.h"
using namespace Cephei::QL::Models;
#include <gen/QL/Math/Array.h>
#include <gen/QL/Models/Parameter.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::CNullParameter::CNullParameter () : CParameter(CNullParameter::typeid)
{
    try
    {
#ifdef HANDLE
        _phNullParameter = NULL;
#endif
        _ppNullParameter = new boost::shared_ptr<QuantLib::NullParameter> (new QuantLib::NullParameter ( ));
        SetParameter (boost::dynamic_pointer_cast<QuantLib::Parameter> (*_ppNullParameter));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::CNullParameter::CNullParameter (boost::shared_ptr<QuantLib::NullParameter>& childNative, Object^ owner) : CParameter(CNullParameter::typeid)
{
#ifdef HANDLE
	_phNullParameter = NULL;
#endif
	_ppNullParameter = &childNative;
    _ppParameter = new boost::shared_ptr<QuantLib::Parameter> (boost::dynamic_pointer_cast<QuantLib::Parameter> (*_ppNullParameter));
}
Cephei::QL::Models::CNullParameter::CNullParameter (QuantLib::NullParameter& childNative, Object^ owner) : CParameter(CNullParameter::typeid)
{
#ifdef HANDLE
	_phNullParameter = NULL;
#endif
	_ppNullParameter = new boost::shared_ptr<QuantLib::NullParameter> (&childNative);
    _ppParameter = new boost::shared_ptr<QuantLib::Parameter> (boost::dynamic_pointer_cast<QuantLib::Parameter> (*_ppNullParameter));
    _NullParameterOwner = owner;
    _ParameterOwner = owner;
}

Cephei::QL::Models::CNullParameter::CNullParameter (CNullParameter^ copy) : CParameter(CNullParameter::typeid)
{
#ifdef HANDLE
	_phNullParameter = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppNullParameter = new boost::shared_ptr<QuantLib::NullParameter> (copy->GetShared());
        _ppParameter = new boost::shared_ptr<QuantLib::Parameter> (boost::dynamic_pointer_cast<QuantLib::Parameter> (*_ppNullParameter));
    }
}
Cephei::QL::Models::CNullParameter::CNullParameter (System::Type^ t) : CParameter(CNullParameter::typeid)
{
#ifdef HANDLE
	_phNullParameter = NULL;
#endif
	if (!t->IsSubclassOf(CNullParameter::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::CNullParameter::CNullParameter (QuantLib::Handle<QuantLib::NullParameter>& childNative, Object^ owner)  : CParameter(CNullParameter::typeid)
{
	_phNullParameter = &childNative;
	_ppNullParameter = &static_cast<boost::shared_ptr<QuantLib::NullParameter>>(childNative.currentLink());
    _ppParameter = new boost::shared_ptr<QuantLib::Parameter> (boost::dynamic_pointer_cast<QuantLib::Parameter> (*_ppNullParameter));
    _NullParameterOwner = owner;
}
Cephei::QL::Models::CNullParameter::CNullParameter (QuantLib::Handle<QuantLib::NullParameter> childNative)  : CParameter(CNullParameter::typeid)
{
	_phNullParameter = &childNative;
	_ppNullParameter = &static_cast<boost::shared_ptr<QuantLib::NullParameter>>(childNative.currentLink());
    _ppParameter = new boost::shared_ptr<QuantLib::Parameter> (boost::dynamic_pointer_cast<QuantLib::Parameter> (*_ppNullParameter));
}
#endif
#ifdef STRUCT
Cephei::QL::Models::CNullParameter::CNullParameter (QuantLib::NullParameter childNative)  : CParameter(CNullParameter::typeid)
{
#ifdef HANDLE
	_phNullParameter = NULL;
#endif
	_ppNullParameter = new boost::shared_ptr<QuantLib::NullParameter> (new QuantLib::NullParameter (childNative));
    _ppParameter = new boost::shared_ptr<QuantLib::Parameter> (boost::dynamic_pointer_cast<QuantLib::Parameter> (*_ppNullParameter));
}
#endif

Cephei::QL::Models::CNullParameter::~CNullParameter ()
{
    if (_ppNullParameter != NULL)
    {
	    delete _ppNullParameter;
        _ppNullParameter = NULL;
    }
}
Cephei::QL::Models::CNullParameter::!CNullParameter ()
{
    if (_ppNullParameter != NULL)
    {
	    delete _ppNullParameter;
    }
}
QuantLib::NullParameter& Cephei::QL::Models::CNullParameter::GetReference ()
{
    if (_ppNullParameter == NULL) throw gcnew NativeNullException ();
	return **_ppNullParameter;
}
boost::shared_ptr<QuantLib::NullParameter>& Cephei::QL::Models::CNullParameter::GetShared ()
{
    if (_ppNullParameter == NULL) throw gcnew NativeNullException ();
	return *_ppNullParameter;
}
QuantLib::NullParameter* Cephei::QL::Models::CNullParameter::GetPointer ()
{
    if (_ppNullParameter == NULL) throw gcnew NativeNullException ();
	return &**_ppNullParameter;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::NullParameter>& Cephei::QL::Models::CNullParameter::GetHandle ()
{
	if (_phNullParameter == NULL)
	{
		_phNullParameter = new Handle<QuantLib::NullParameter> (*_ppNullParameter);
	}
	return *_phNullParameter;
}
#endif
bool Cephei::QL::Models::CNullParameter::HasNative () 
{
	return (_ppNullParameter != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Models::INullParameter^ Cephei::QL::Models::CNullParameter_Factory::Create ()
{
    return gcnew CNullParameter ();
}
